package com.xydtech.ecard.merchant.service.impl;

import com.xydtech.common.annotation.DataScope;
import com.xydtech.common.core.domain.entity.SysDictData;
import com.xydtech.ecard.merchant.domain.EcardBranchMerchantPrd;
import com.xydtech.ecard.merchant.mapper.EcardBranchMerchantPrdMapper;
import com.xydtech.ecard.merchant.service.IEcardBranchMerchantPrdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/*
 * 网点营销商户产品信息统计Service
 *@author lin
 *@version 1.0
 *@create 2023/8/3 9:00
 */
@Service
public class EcardBranchMerchantPrdServiceImpl implements IEcardBranchMerchantPrdService {

    @Autowired
    private EcardBranchMerchantPrdMapper ecardBranchMerchantPrdMapper;
    /**
     * 网点建档商户信息统计
     * @param ecardBranchMerchantPrd
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectBranchMerchantPrdInfo(EcardBranchMerchantPrd ecardBranchMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardBranchMerchantPrds = ecardBranchMerchantPrdMapper.selectBranchMerchantPrdInfo(ecardBranchMerchantPrd);
        for (LinkedHashMap<String, Object> branchMerchantPrdMap : ecardBranchMerchantPrds) {
            String deptId = String.valueOf(branchMerchantPrdMap.remove("dept_id"));
            String deptName = String.valueOf(branchMerchantPrdMap.remove("dept_name"));
            branchMerchantPrdMap.put("机构名称", deptName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardBranchMerchantPrdMapper.selectBranchPrdByBusinessLabel(dictValue, String.valueOf(deptId));
                if (nums == null){
                    nums = 0;
                }
                branchMerchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardBranchMerchantPrds;
    }

    /**
     * 网点营销企业产品信息统计
     * @param ecardBranchMerchantPrd
     * @param sysDictDataList
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectBranchEnterprisePrdInfo(EcardBranchMerchantPrd ecardBranchMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardBranchMerchantPrds = ecardBranchMerchantPrdMapper.selectBranchEnterprisePrdInfo(ecardBranchMerchantPrd);
        for (LinkedHashMap<String, Object> branchMerchantPrdMap : ecardBranchMerchantPrds) {
            String deptId = String.valueOf(branchMerchantPrdMap.remove("dept_id"));
            String deptName = String.valueOf(branchMerchantPrdMap.remove("dept_name"));
            branchMerchantPrdMap.put("机构名称", deptName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardBranchMerchantPrdMapper.selectBranchEntPrdByBusinessLabel(dictValue, String.valueOf(deptId));
                if (nums == null){
                    nums = 0;
                }
                branchMerchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardBranchMerchantPrds;
    }

    /**
     * 网点营销农业产品信息统计
     * @param ecardBranchMerchantPrd
     * @param sysDictDataList
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectBranchAgriculturePrdInfo(EcardBranchMerchantPrd ecardBranchMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardBranchMerchantPrds = ecardBranchMerchantPrdMapper.selectBranchAgriculturePrdInfo(ecardBranchMerchantPrd);
        for (LinkedHashMap<String, Object> branchMerchantPrdMap : ecardBranchMerchantPrds) {
            String deptId = String.valueOf(branchMerchantPrdMap.remove("dept_id"));
            String deptName = String.valueOf(branchMerchantPrdMap.remove("dept_name"));
            branchMerchantPrdMap.put("机构名称", deptName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardBranchMerchantPrdMapper.selectBranchAgrPrdByBusinessLabel(dictValue, String.valueOf(deptId));
                if (nums == null){
                    nums = 0;
                }
                branchMerchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardBranchMerchantPrds;
    }

    /**
     * 网点营销个人产品信息统计
     * @param ecardBranchMerchantPrd
     * @param sysDictDataList
     * @return
     */
    @Override
    @DataScope(deptAlias = "aa")
    public List<LinkedHashMap<String, Object>> selectBranchPersonPrdInfo(EcardBranchMerchantPrd ecardBranchMerchantPrd, List<SysDictData> sysDictDataList) {
        //改为根据字典展示对应字段
        List<LinkedHashMap<String, Object>> ecardBranchMerchantPrds = ecardBranchMerchantPrdMapper.selectBranchPersonPrdInfo(ecardBranchMerchantPrd);
        for (LinkedHashMap<String, Object> branchMerchantPrdMap : ecardBranchMerchantPrds) {
            String deptId = String.valueOf(branchMerchantPrdMap.remove("dept_id"));
            String deptName = String.valueOf(branchMerchantPrdMap.remove("dept_name"));
            branchMerchantPrdMap.put("机构名称", deptName);
            for (SysDictData sysDictData : sysDictDataList) {
                String dictValue = sysDictData.getDictValue();
                Integer nums = ecardBranchMerchantPrdMapper.selectBranchPerPrdByBusinessLabel(dictValue, String.valueOf(deptId));
                if (nums == null){
                    nums = 0;
                }
                branchMerchantPrdMap.put(sysDictData.getDictLabel(),nums);
            }
        }
        return ecardBranchMerchantPrds;
    }

}
